package tk.pixilab.android;

import java.util.Random;

import android.app.Activity;
import android.graphics.drawable.AnimationDrawable;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class CoinActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        final Drawable kopf = (Drawable)getResources().getDrawable(R.drawable.coin_1);
        final Drawable zahl = (Drawable)getResources().getDrawable(R.drawable.coin_5);
        final AnimationDrawable animation = (AnimationDrawable)getResources().getDrawable(R.drawable.coin_animation);
        final Button btn_coin = (Button)findViewById(R.id.main_btn_coin);
        btn_coin.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				int random = animation.isRunning()?new Random().nextInt(2):2;
				switch(random) {
					case 0:{
						animation.stop();
						btn_coin.setBackgroundDrawable(kopf);
						break;
					}
					case 1:{
						animation.stop();
						btn_coin.setBackgroundDrawable(zahl);
						break;
					}
					case 2:{
						btn_coin.setBackgroundDrawable(animation);
						animation.start();
						break;
					}
				}
				
			}
		});
    }
}